﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DbGenerator.Model.units.column;
using DbGenerator.Model.units.table;

namespace DbExecuter.DataLayer.commands
{
    public class TSelectClause
    {
        #region ctors
        public TSelectClause(TColumn[] selectColumns)
        {
            _SelectColumns = selectColumns;
        }
        #endregion

        #region overriden methods
        public override string ToString()
        {
            // SELECT D.[ID] AS id, G.[Name] AS İsim
            StringBuilder sb = new StringBuilder();
            int selectColumnCount = _SelectColumns.Length;

            sb.Append("SELECT ");
            for (int i = 0; i < selectColumnCount; i++)
            {
                sb.AppendFormat("\n\t{0}.[{1}] {2}, "
                    , _SelectColumns[i].BaseTable.TableSign.TableAlias
                    , _SelectColumns[i].ColumnInfo.ColumnName
                    , String.Format("AS [{0}]", _SelectColumns[i].ColumnAlias.Alias));
            }
            sb.Remove(sb.Length - 2, 2);
            sb.Append("\n");
            return sb.ToString();
        }
        #endregion

        #region properties
        private TColumn[] _SelectColumns;
        public TColumn[] SelectColumns
        {
            get { return _SelectColumns; }
        }
        #endregion
    }
}
